<?php
require_once '../PHPMailer_master/PHPMailerAutoload.php';
require_once '../PHPMailer_master/class.phpmailer.php';
require_once '../PHPMailer_master/class.smtp.php';
require_once '../inc/configuration.php';
require_once '../inc/connexion_db.php';
require_once '../inc/fonctions_identification.php';

// avec utilisation des cookies
proteger_page("login", CHEMIN);


if(isset($_GET["id"])) {
    $id = $_GET["id"];
}
else if(isset($_POST["id"])) {
    $id = $_POST["id"];
}
else {
    $id = "";
}


$sql = "SELECT * FROM contacts WHERE id=".$id;
$req = mysqli_query($connexion_bd, $sql);
$data = mysqli_fetch_array($req);


$mail = new PHPMailer();


$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host =  '';                                     // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '';                           // SMTP username
$mail->Password = '';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

$mail->From = '';
$mail->FromName = '';
$mail->addAddress($data["email"]);
//$mail->addAddress('a.armstrong@free.fr', '');         // Add a recipient
//$mail->addAddress('ellen@example.com');               // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'test phpMailer';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
